package jindu

import (
	"fmt"
	"io"
	"os"
	"time"
)

func process(ch chan int64)  {
	for rate:=range ch{
		fmt.Printf("\b\b\b%d%%",rate)
	}
}

func Jindu(){
	var ch  = make(chan int64)
	defer close(ch)
	f, _ := os.Open("./tmp/mysql-bin.001252")
	defer f.Close()
	go process(ch)
	info,_ := f.Stat()
	size :=info.Size()
	ret := make([]byte, 0)
	fmt.Print("rate:0%")
	var showNum int64 = 0
	for {
		var buf = make([]byte, 1024*100000)
		n, err := f.Read(buf)
		if err != nil && err != io.EOF {
			panic(err)
		}
		if n == 0 {
			break
		}
		time.Sleep(time.Second)
		showNum = showNum + int64(len(buf)*100)/size
		//go func() {
			ch<-showNum
		//}()
		ret = append(ret, buf...)
	}
	//ioutil.WriteFile("./tmp/ret", ret, os.ModeAppend)
}